﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using EF_Model;
using Moq;
using System;
using System.Data.Objects;

namespace EF_Tests
{
    [TestClass]
    public class Repository_Read_Logic_Test
    {
        /// <summary>
        /// the reason to use a fake class, is using Concrete Object set hooks into database, 
        /// and ObjectSet.AddObject really not get searchable until committed to database.
        /// </summary>
        [TestMethod]
        public void Read_Test_With_Concrete_Mock_Context_And_Fake_ObjectSet_Implementation_With_Mock_Setup()
        {
            Mock<DatabaseContext> dbContext = new Mock<DatabaseContext>();
            CustomerRepository cr = new CustomerRepository(dbContext.Object);

            Customer c = new Customer();
            c.CustomerID = "118";
            c.ContactName = "xxx-118";
            c.CompanyName = "com-001";

            var customerObjectSet = new FakeObjectSet<Customer>();
            customerObjectSet.AddObject(c);

            dbContext.Setup(db => db.Customers).Returns(customerObjectSet);

            Console.Write(cr.GetById("118").ContactName);//passes
        }
    }
}
